#include <iostream>
#include <stack>
#include <unordered_map>
using namespace std;

bool isValidBrackets(const string& sequence) {
    stack<char> stk;
    unordered_map<char, char> bracketsMap = {
        {')', '('},
        {']', '['},
        {'}', '{'},
        {'>', '<'}
    };

    for (char bracket : sequence) {
        if (bracket == '(' || bracket == '[' || bracket == '{' || bracket == '<') {
            stk.push(bracket);
        } else if (bracket == ')' || bracket == ']' || bracket == '}' || bracket == '>') {
            if (stk.empty() || bracketsMap[bracket] != stk.top()) {
                return false;
            }
            stk.pop();
        }
    }

    return stk.empty();
}

int main() {
    string bracketSequence;
    cout << "Введите скобочную последовательность: ";
    cin >> bracketSequence;

    bool isValid = isValidBrackets(bracketSequence);
    cout << boolalpha << isValid << endl;

    return 0;
}